@(account: Option[gitbucket.core.model.Account], extraMailAddresses: List[String], error: Option[Any] = None)(implicit context: gitbucket.core.controller.Context)
@gitbucket.core.html.main(if(account.isEmpty) "New user" else "Update user"){
  @gitbucket.core.admin.html.menu("users"){
    @gitbucket.core.helper.html.error(error)
    <form method="POST" validate="true" autocomplete="off">
      <div class="row">
        <div class="col-md-6">
          <fieldset class="form-group">
            <label for="userName" class="strong">Username:</label>
            <div>
              <span id="error-userName" class="error"></span>
            </div>
            <input type="text" name="userName" id="userName" class="form-control" value="@account.map(_.userName)"@if(account.isDefined){ readonly}/>
            @if(account.isDefined){
              <label for="removed">
                <input type="checkbox" name="removed" id="removed" value="true" @if(account.get.isRemoved){checked}/>
                Disable
              </label>
              <div>
                <span id="error-removed" class="error"></span>
              </div>
            }
          </fieldset>
          @if(account.map(_.password.nonEmpty).getOrElse(true)){
            <fieldset class="form-group">
              <label for="password" class="strong">
                Password
                @if(account.isDefined){
                  (Input to change password)
                }
                :
              </label>
              <div>
                <span id="error-password" class="error"></span>
              </div>
              <input type="password" name="password" id="password" class="form-control" value="" autocomplete="off"/>
            </fieldset>
          }
          <fieldset class="form-group">
            <label for="fullName" class="strong">Full Name:</label>
            <div>
              <span id="error-fullName" class="error"></span>
            </div>
            <input type="text" name="fullName" id="fullName" class="form-control" value="@account.map(_.fullName)"/>
          </fieldset>
          <fieldset class="form-group">
            <label for="mailAddress" class="strong">Mail Address:</label>
            <div>
              <span id="error-mailAddress" class="error"></span>
            </div>
            <input type="text" name="mailAddress" id="mailAddress" class="form-control" value="@account.map(_.mailAddress)"/>
          </fieldset>
          <fieldset class="form-group" id="extraMailAddresses">
            <span class="strong">Additional Mail Address:</span>
            @extraMailAddresses.zipWithIndex.map { case (mail, idx) =>
            <input type="text" name="extraMailAddresses[@idx]" id="extraMailAddresses[@idx]" class="form-control extraMailAddress" value="@mail" aria-label="Additional mail address"/>
            <span id="error-extraMailAddresses_@idx" class="error"></span>
            }
          </fieldset>
          <fieldset class="form-group">
            <label class="strong">User Type:</label>
            <label class="radio" for="userType_Normal">
              <input type="radio" name="isAdmin" id="userType_Normal" value="false"@if(account.isEmpty || !account.get.isAdmin){ checked}/> Normal
            </label>
            <label class="radio" for="userType_Admin">
              <input type="radio" name="isAdmin" id="userType_Admin" value="true"@if(account.isDefined && account.get.isAdmin){ checked}/> Administrator
            </label>
          </fieldset>
          <fieldset class="form-group">
            <label class="strong" for="url">URL (Optional):</label>
            <div>
              <span id="error-url" class="error"></span>
            </div>
            <input type="text" name="url" id="url" class="form-control" value="@account.map(_.url)"/>
          </fieldset>
          <fieldset class="form-group">
            <label class="strong" for="description">Bio (Optional):</label>
            <div>
              <span id="error-description" class="error"></span>
            </div>
            <textarea name="description" id="description" class="form-control">@account.map(_.description)</textarea>
          </fieldset>
        </div>
        <div class="col-md-6">
          <fieldset class="form-group">
            <label for="avatar" class="strong">Image (Optional)</label>
            @gitbucket.core.helper.html.uploadavatar(account)
          </fieldset>
        </div>
      </div>
      <fieldset class="border-top">
        @if(account.isEmpty){
          <input type="submit" class="btn btn-success" value="Create user" formaction="@context.path/admin/users/_newuser"/>
        } else {
          <input type="submit" class="btn btn-success" value="Update user" formaction="@context.path/admin/users/@account.get.userName/_edituser" id="update"/>
        }
        <a href="@context.path/admin/users" class="btn btn-default">Cancel</a>
      </fieldset>
    </form>
  }
}
<script>
$(function(){
  addExtraMailAddress();
  $('#extraMailAddresses').on('change', '.extraMailAddress', checkExtraMailAddress);
  $('#update').click(function(){
    if($('#password').val() != ''){
      return confirm('Are you sure you want to change password of this user?');
    } else {
      return true;
    }
  });
});
</script>
